package org.example.sboot.service.impl;

import org.example.sboot.entity.Tabledata;
import org.example.sboot.entity.TabledataExample;
import org.example.sboot.mapper.TabledataMapper;
import org.example.sboot.service.CounlistService;
import org.example.sboot.service.TabledataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jia
 * @date 2021/6/13
 */
@Service
public class TabledataImpl implements TabledataService {
    @Autowired
    private TabledataMapper mapper;


    @Override
    public List<Tabledata> selectTabledataList(Tabledata tabledata) {

        return mapper.selectTableList(tabledata);

    }

    @Override
    public Tabledata selectTabledataByName(String name) {
        TabledataExample example = new TabledataExample();
        if (name != null && name.length() > 0) {
            TabledataExample.Criteria criteria = example.createCriteria();
            criteria.andNameEqualTo(name);
            List<Tabledata> tabledataList = mapper.selectByExample(example);

            return tabledataList.get(0);

        }
        return mapper.selectByExample(null).get(0);

    }

    @Override
    public int insert(Tabledata record) {
        return mapper.insert(record);
    }

    @Override
    public int updateByExample(Tabledata tabledata) {
        TabledataExample example = new TabledataExample();
        TabledataExample.Criteria criteria =
                example.createCriteria();
        return mapper.updateByPrimaryKey(tabledata);

    }

    @Override
    public Tabledata selectByPrimaryKey(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteByPrimaryKey(Long[] ids) {
        int i1 = 0;
        for (int i = 0; i < ids.length; i++) {
            i1 = mapper.deleteByPrimaryKey(Integer.valueOf(String.valueOf(ids[i])));
        }
        return i1;
    }
}
